<?php

class PC4_Controlador_APP_CRUD_Newsletters extends PC4_Controlador_APP_CRUD {
	
	protected function init($modelo = '', $formView = 'admin/newsletters', $listaView = '', $editaView = '', $nomeSessao = 'usuarios', $urlLogin = 'admin/login/', $urlProibido = 'admin/main/proibido') {
		if (empty($modelo)) {
			$modelo = new PC4_Crud_Newsletter('newsletters', array('nome' => 'requerida', 'email' => array('requerida', 'unica')));
		}
		parent::init($modelo, $formView, $listaView, $editaView, $nomeSessao, $urlLogin, $urlProibido);
		$this->layout->addJS("app/admin.newsletter.js");
	}
	
	public function geraPlanilha(){
		$excel = new PC4_Util_Excel();
		$this->layout->view = "blank";
		$rs = $this->modelo->consulta(array('ativo' => 1), 1, -1);

		foreach ($rs as $r) {
			$resultado[] = array(
				'nome' => $r->nome,
				'email' => $r->email
			);
		}
//		$cabecalhos = array("nome" => "Nome", "email" => "Email");
		
		echo $excel->exporta($resultado, array(), 'csv');
	}

}
?>